<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>角色添加</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="/layer/layer.js"></script>
</head>
<body>

<div class="container" id="roleAdd">
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <form class="form-horizontal" action="" method="post">
        <h2 class="form-signin-heading" style="color: black">角色添加</h2>

        <div class="form-group">
            <label for="inputPassword3" class="col-sm-2 control-label">角色身份</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="inputPassword3" v-model="roleInfo.name">
            </div>
        </div>

        <div class="form-group">
            <label for="remark" class="col-sm-2 control-label">备注</label>
            <div class="col-sm-10">
                <textarea class="form-control" id="remark" v-model="roleInfo.remark"></textarea>
            </div>
        </div>

        <div>
            <button class="btn btn-lg btn-primary btn-block" type="button"
                    @click="addRole()" style="width: 100%">提交
            </button>
        </div>
    </form>
</div>

<script>
    new Vue({
        el: "#roleAdd",
        data: {
            roleInfo: {}
        },
        methods: {
            //添加用户
            addRole() {
                var vm = this;
                $.post("/role/add", vm.roleInfo, function (response) {
                    if (response.code == 200) {
                        layer.msg('提交成功！', {
                            time: 1000,
                            end: function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name)),
                                    vm.loadData();
                                //    存在小页面的话，该语句是关闭页面的
                            }
                        })
                    } else {
                        layer.msg('提交失败！', {
                            time: 1000,
                        })
                    }
                })
            }
        }
    })
</script>
</body>
</html>